package cc.lj.internal.core.http;

import lombok.Data;

/**
 * 统一返回结果集实体类
 * @param <T> 返回数据对象t
 */
@Data
public class HttpResult<T> {
    //错误码
    private Integer code;

    //错误信息，一般为前端提示信息
    private String message;

    //返回值，一般为成功后返回的数据
    private T data;

    //错误详情，一般为失败后的详细原因，如空指针之类的
    private String errorDetail;

    public HttpResult() {}

    public HttpResult(Integer retCode, String retMsg) {
        this.code = retCode;
        this.message = retMsg;
    }

    public HttpResult(Integer retCode, String retMsg, T data) {
        this.code = retCode;
        this.message = retMsg;
        this.data = data;
    }


    public static <T> HttpResult<T> success(Integer retCode,String retMsg, T data)
    {
        HttpResult<T> httpResult = new HttpResult<>();
        httpResult.code = retCode;
        httpResult.message = retMsg;
        httpResult.data = data;
        return httpResult;
    }

    public static <T> HttpResult<T> error(Integer retCode,String retMsg,String errorDetail)
    {
        HttpResult<T> httpResult = new HttpResult<>();
        httpResult.code = retCode;
        httpResult.message = retMsg;
        httpResult.errorDetail = errorDetail;
        return httpResult;
    }
    public static final HttpResult SERVICE_FUSING = new HttpResult(603, "服务熔断");

}
